package com.zhouyang.bootssh.controller;


import com.zhouyang.bootssh.api.books.UserControllerApi;
import com.zhouyang.bootssh.entity.books.User;
import com.zhouyang.bootssh.entity.books.UserExample;
import com.zhouyang.bootssh.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

import java.util.List;

/**
 * @Auther: 周洋
 * @Date: 2018/11/6 15:51
 * @Description:
 */
@Controller
public class UserController implements UserControllerApi {


    @Autowired
    private UserService userService;

    @Override
    public String showUser(User user, Model model){
        System.out.println("user");
        System.out.println(user);
        int insert = userService.insert(user);
        System.out.println(insert);
        return "index";
    }
    @Override
    public String selectUser(Model model){
        UserExample example=new UserExample();
//        UserExample.Criteria criteria = example.createCriteria();
//        criteria.andNameLike()
        List<User> users = userService.selectByExample(example);
        model.addAttribute("users",users);
        return "showUser";
    }

    @Override
    public List<User> ajaxSelectUser(){
        UserExample example=new UserExample();
        List<User> users = userService.selectByExample(example);
        return users;
    }
}
